package com.Lyy.Controller;

import com.Lyy.Entity.Book;
import com.Lyy.Entity.RR;
import com.Lyy.Service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Component
//@Controller
//@ResponseBody
@RestController
@CrossOrigin
@RequestMapping(produces = "application/json;charset=utf-8")
public class BookController {
    @Autowired
    public BookService bookService;

    public RR T(Object result) {
        return new RR(200,result);
    }

    public RR F() {
        return new RR(500, "F");
    }

    @RequestMapping("/SelectBookAll")
//    http://localhost/SelectBookAll
    public List<Book> SelectBookAll() {
        return bookService.SelectBookAll();
    }

    @RequestMapping("/SelectBookByName")
//    http://localhost/SelectBookByName?bookName=与
    public List<Book> SelectBookByName(String bookName) {
        return bookService.SelectBookByName(bookName);
    }

    @RequestMapping("/SelectBookById")
//    http://localhost/SelectBookById?id=3
    public Book SelectBookById(int id) {
        return bookService.SelectBookById(id);
    }

    @RequestMapping("/UpdateBook")
//    http://localhost/UpdateBook
    public int UpdateBook(@RequestBody Book book) {
        return bookService.UpdateBook(book);
    }

    @RequestMapping("/DeleteBook")
//    http://localhost/DeleteBook?id=5
    public int DeleteBook(int id) {
        return bookService.DeleteBook(id);
    }

    @RequestMapping("/InsertBook")
//    http://localhost/InsertBook
    public int InsertBook(Book book) {
        return bookService.InsertBook(book);
    }
}
